package com.example.horizonserver.controller;


import com.example.horizonserver.common.result.PageResult;
import com.example.horizonserver.common.result.Result;
import com.example.horizonserver.pojo.DTO.VehicleDTO;
import com.example.horizonserver.pojo.DTO.VehiclePageQueryDTO;
import com.example.horizonserver.pojo.entity.Vehicle;
import com.example.horizonserver.service.VehicleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/vehicles")
public class VehicleController {

    @Autowired
    private VehicleService vehicleService;

    /**
     * 新增车辆信息
     * @param vehicleDTO
     * @return
     */
    @PostMapping
    public Result<String> save(@RequestBody VehicleDTO vehicleDTO)
    {
        vehicleService.save(vehicleDTO);
        return Result.success();
    }

    /**
     * 车辆条件分页查询
     * @param vehiclePageQueryDTO
     * @return
     */
    @GetMapping("/page")
    public Result<PageResult> page(VehiclePageQueryDTO vehiclePageQueryDTO)
    {
        PageResult pageResult = vehicleService.pageQuery(vehiclePageQueryDTO);
        return Result.success(pageResult);
    }

    /**
     * 车辆批量删除
     *
     * @param ids
     * @return
     */
    @DeleteMapping
    public Result<String> delete(@RequestParam List<Integer> ids) {
        vehicleService.deleteBatch(ids);
        return Result.success();
    }

    /**
     * 根据id查询车辆信息 用作修改回显 以及申请使用时的信息显示
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public Result<Vehicle> getById(@PathVariable Integer id)
    {
        Vehicle vehicle = vehicleService.getById(id);
        return Result.success(vehicle);
    }


    /**
      * 修改车辆信息
     * @param vehicleDTO
     * @return
     */
    @PutMapping
    public Result<String> update(@RequestBody VehicleDTO vehicleDTO)
    {
        vehicleService.update(vehicleDTO);
        return Result.success();
    }



}
